<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<!--公共JS开始-->
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<!--公共JS结束-->
<!--数据列表插件开始-->
<link href="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.ui.position.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.js"></script>
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Css/etgrid.css">
<script src="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Js/etgrid.js"></script>
<!--数据列表插件结束-->
<style type="text/css">
	body {
		overflow:hidden;
	}
	.table_box {
	}
</style>
</head>

<body>
	<div class="page_header">
		<div class="table_tool">
			<ul class="clearfix">
				<li class="memberDel btn"><i class="icon-remove"></i> 批量删除</li>
				<li class="line"></li>
				<li class="openwin btn" etitle="新增积分礼品" eheight="300px" ewidth="900px" ehref="{:U('Integral/add')}" id="Integral_add"><i class="icon-plus"></i> 新增积分礼品</li>			
			</ul>
		</div>
		<div class="search_box">
			餐厅名称：
			<select name="restid" id="restid" class="form_ele">
				<option value="">请选择</option>
				<volist name="list" id="vo">
					<option value="{$vo.id}">{$vo.title}（{$vo.entitle}）</option>
				</volist>
			</select>
		</div>
	</div>
	<div class="table_box">
	</div>
</body>
<script type="text/javascript">
	var listConfig = {
			blockBox : '.table_box',
			blockBoxHeight : 'window',
			jsonUrl : '__URL__/index/id/{$id}',
			where : '',
			getWhere : function(){
				return getwheres();
			},
			showPageNav: false,
			widthType : 'tdw', //thw-标题标准宽度、tdw-数据单元标准宽度、auto-随数据单元宽度
			pageNum : 10,
			nowPage : 1,
			orderName : "addtime",
			orderDirection : "desc",
			dataContextMenuOpen: true, //是否开启数据行右键菜单
			showPageNav: true,         //是否显示分页
			dataContextMenu: function(){
				$.contextMenu({
					selector: '.et_tbody tr',
					items: {
						"edit": {
							name: "修改", 
							icon: "edit",
							callback: function(key, options) {
								var href = "{:U('Integral/edit')}&id="+$(this).attr('rowid');
								var width = '900px';
								var height = '300px';
								var title = '修改积分礼品';
								openDialog('Integral_edit',href,width,height,title);
							}
						},
						"delete": {
							name: "删除", 
							icon: "del",
							callback: function(key, options) {
								var id = $(this).attr('rowid');
								$.get("{:U('Integral/del')}",{ id: id },function(data){
									windowApi.lhgdialog.tips('数据删除成功！');
									$('.et_tfoot .page_refresh').click(); //刷新加载
								});
							}
						}
					}
				});
			},
			colModel : [
				{
					display : 'checkbox',
					name : 'id',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '所属餐厅',
					name : 'rtitle',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '积分礼品中文名称',
					name : 'title',
					sortable : true,
					myclass : 'center',
					width   : '120px',
					edit : false
				},
				{
					display : '积分礼品英文名称',
					name : 'entitle',
					sortable : true,
					myclass : 'center',
					width   : '120px',
					edit : false
				},
				{
					display : '所需积分',
					name : 'integration',
					sortable : true,
					myclass : 'center',
					width   : '80px',
					edit : false
				},
				{
					display : '兑换人数',
					name : 'amount',
					sortable : true,
					myclass : 'center',
					width   : '80px',
					edit : false
				},
				{
					display : '时间',
					name : 'addtime',
					sortable : true,
					myclass : 'center',
					edit : false
				}
			]
		};
	
	//实例化列表
	var tableList = $('.table_box').EtGrid(listConfig);
	
	$(function(){
		
		//根据餐厅筛选
		$('#restid>option').each(function(){
			$(this).on('click',function(){
				byCondition();
			});
		});
		
		//根据菜系筛选
		$('#cuisineid>option').each(function(){
			$(this).on('click',function(){
				byCondition();
			});
		});
		
		//根据是否推荐筛选
		$('#isrecommend>option').each(function(){
			$(this).on('click',function(){
				byCondition();
			});
		});
		
		//根据品牌类型筛选
		$('#type>option').each(function(){
			$(this).on('click',function(){
				byCondition();
			});
		});
		
		//重置搜索条件
		$("#doRest").on("click",function(){
			clearwheres();
			byCondition();
		});
		
		//批量删除
		$('.memberDel').on('click',function(){
			
			var val = tableList.getChecked();
			var msg = "确认要将选中的积分礼品删除吗？";
			
			if(val){
				
				windowApi.lhgdialog.confirm(msg, function(){
					
					$.post("{:U('Integral/delall')}",{val:val},function(data){
						if(data.status==1){
							$('.et_tfoot .page_refresh').click(); //刷新加载
						}else{
							windowApi.lhgdialog.alert(data.info,function(){return;});
						}
					});
				},'json');
			}else{
				
				windowApi.lhgdialog.alert('请选择需要删除的积分礼品！');
			}
		});
		
	});
	
	//获取筛选条件并组成数组
	function getwheres(){
		
		var where  = {};
		
		where.restid       = $('#restid').val();
		where.cuisineid    = $('#cuisineid').val();
		where.isrecommend  = $('#isrecommend').val();
		where.type         = $('#type').val();
		
		return where;
	}
	
	//重置搜索条件
	function clearwheres(){
		
		$('#restid').val("");
		$('#cuisineid').val("");
		$('#isrecommend').val("");
		$('#type').val("");
	}
	//发送异步进行搜索
	function byCondition(){
		
		var where = tableList.config.getWhere();
		tableList.config.where = where;
		tableList.search();
	}
	//tableList.erefresh();
</script>
</html>
